package com.wangzeqi.changliaoba.myself;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.easemob.chat.EMChat;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMCmdManager;
import com.wangzeqi.changliaba.dao.User;
import com.wangzeqi.changliaoba.R;
import com.wangzeqi.changliaoba.base.BaseFragment;
import com.wangzeqi.changliaoba.login.EnterActivity;
import com.wangzeqi.changliaoba.util.DataCleanManager;
import com.wangzeqi.custom.CircleImageView;


/**
 * Created by dllo on 16/2/29.
 */
public class MyselfFragment extends BaseFragment implements View.OnClickListener {
    private LinearLayout me_ll;
    private TextView me_play, me_favorites, me_package, clean_cache, me_expression, me_set, cache_data, me_name, me_num;
    private DataCleanManager dataCleanManager;
    private CircleImageView me_icon;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_myself, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        me_play = (TextView) view.findViewById(R.id.me_play);
        me_favorites = (TextView) view.findViewById(R.id.me_favorites);
        me_package = (TextView) view.findViewById(R.id.me_package);
        me_expression = (TextView) view.findViewById(R.id.me_package);
        clean_cache = (TextView) view.findViewById(R.id.clean_cache);
        cache_data = (TextView) view.findViewById(R.id.cache_data);
        me_set = (TextView) view.findViewById(R.id.me_set);
        me_ll = (LinearLayout) view.findViewById(R.id.me_ll);
        me_name = (TextView) view.findViewById(R.id.me_name);
        me_num = (TextView) view.findViewById(R.id.me_num);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        try {
            cache_data.setText(dataCleanManager.getTotalCacheSize(getActivity()));
        } catch (Exception e) {
            e.printStackTrace();
        }

        me_num.setText(EMChatManager.getInstance().getCurrentUser());
        me_set.setOnClickListener(this);
        clean_cache.setOnClickListener(this);
        me_ll.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.me_set:
                Intent intent = new Intent(getActivity(), SetAvtivity.class);
                getActivity().startActivity(intent);
                break;
            case R.id.clean_cache:
                dataCleanManager.clearAllCache(getActivity());
                break;
            case R.id.me_ll:
                Intent intent_ = new Intent(getActivity(), PersonalDetailActivity.class);
                getActivity().startActivity(intent_);
                break;
        }
    }

}
